package com.main.login.domain.user.service;

import com.main.common.base.base.BaseAssemblerFactory;
import com.main.common.base.resp.RespBody;
import com.main.common.interfaces.AccessLimit;
import com.main.login.application.service.AccountService;
import com.main.login.domain.user.aggregates.Account;
import com.main.login.domain.user.repository.AccountRepository;
import com.main.login.interfaces.assembler.AccountAssembler;
import com.main.login.interfaces.assembler.AddAccountAssembler;
import com.main.login.interfaces.dto.AccountDTO;
import com.main.login.interfaces.dto.AddAccountDTO;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountRepository accountRepository;
    @Autowired
    private BaseAssemblerFactory baseAssemblerFactory;

    public RespBody<AddAccountDTO> addAccount(AddAccountDTO addAccountDTO) {
        AddAccountAssembler addAccountAssembler = new AddAccountAssembler(baseAssemblerFactory);
        Account account = addAccountAssembler.toEntity(addAccountDTO);
        System.out.println(account);
        accountRepository.save(account);
        return RespBody.ok(addAccountDTO);
    }

    public RespBody<List<AccountDTO>> getAccountList() {
        List<Account> accountArr = accountRepository.list();
        List<AccountDTO> accountDTOArr = new AccountAssembler().toDTOs(accountArr);
        return RespBody.ok(accountDTOArr);
    }


}
